package edu.hda.pt.server.connections.netty;

import static org.jboss.netty.channel.Channels.pipeline;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;

import edu.hda.pt.server.connections.PTServerNetty;
import edu.hda.pt.utils.connections.netty.codec.MessageDecoder;
import edu.hda.pt.utils.connections.netty.codec.MessageEncoder;

/**
 * Netty pipeline factory for setting the event handler and encoder and decoder
 * 
 * @author Marc Hammerton
 *
 */
public class ServerPipelineFactory implements ChannelPipelineFactory {
	
	private PTServerNetty server;
	
	public ServerPipelineFactory(PTServerNetty server) {
		this.server = server;
	}

	/**
	 * Return the pipeline
	 * 
	 * @see org.jboss.netty.channel.ChannelPipelineFactory#getPipeline()
	 */
	@Override
	public ChannelPipeline getPipeline() throws Exception {
		
		ChannelPipeline pipeline = pipeline();
		
		// Add codecs
		pipeline.addLast("decoder", new MessageDecoder());
		pipeline.addLast("encoder", new MessageEncoder());
		
		pipeline.addLast("handler", new ServerHandler(server));
		
		return pipeline;
	}

}
